<?php
# 文件名称:html.php
# MetInfo在线反馈系统 
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
defined( '_SYS' ) or die( 'No direct script access allowed' );
class C_html
{
	/**
	 * 加载相应的类和函数
	 *
	 * @param	string
	 */
	function _( $type )
	{
		//Initialise variables
		$prefix = 'C_HTML';
		$file   = '';
		$func   = $type;
		// Check to see if we need to load a helper file
		$parts = explode('.', $type);
		switch(count($parts))
		{
			case 3 :
			{
				$prefix		= preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
				$file		= preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
				$func		= preg_replace( '#[^A-Z0-9_]#i', '', $parts[2] );
			} break;
			case 2 :
			{
				$file		= preg_replace( '#[^A-Z0-9_]#i', '', $parts[0] );
				$func		= preg_replace( '#[^A-Z0-9_]#i', '', $parts[1] );
			} break;
		}
		$className	= $prefix.ucfirst($file);
		if (!class_exists( $className ))
		{
			require(PATH_LIBRARIES.DS.'html/html/'.$file.EXT);
		}
		if (is_callable( array( $className, $func ) ))
		{
			$args = func_get_args();
			array_shift( $args );
			return call_user_func_array( array( $className, $func ), $args );
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * 加载脚本文件
	 */
	function script($filename, $path = 'media/system/js/', $mootools = true)
	{
		// Include mootools framework
		if($mootools) {
			C_HTML::_('behavior.mootools');
		}
		if(strpos($path, 'http') !== 0) {
			$path =  SITEURL.'/'.$path;
		};
		$SYS =& get_instance();
		$SYS->doc->addScript( $path.$filename );
		return;
	}
	/**
	 * 加载样式文件
	 */
	function stylesheet($filename, $path = 'media/system/css/', $attribs = array())
	{
		if(strpos($path, 'http') !== 0) {
			$path =  SITEURL.'/'.$path;
		};
		$SYS =& get_instance();
		$SYS->doc->addStylesheet( $path.$filename, 'text/css', 'all', $attribs );
		return;
	}
}
class C_text
{
	function _($string)
	{
		$SYS =&get_instance();
		$index = $SYS->request->getVar('languageID','');
		$lang =&$SYS->lang;
		$tmp = explode(DS,FCPATH);
		array_pop($tmp);
		$is_admin = array_pop($tmp)==$SYS->config->item('administrator_file');
		$index2 = $is_admin?$lang->admin_language:$lang->site_language;
		//后读公共语言
		$string = $lang->item($string,$index)?$lang->item($string,$index):$lang->item($string,$index2);
		return $string;
	}
	function sprintf($string)
	{
		$args = func_get_args();
		if (count($args) > 0) {
			$args[0] = C_text::_($args[0]);
			return call_user_func_array('sprintf', $args);
		}
		return '';
	}
	function printf($string)
	{
		$args = func_get_args();
		if (count($args) > 0) {
			$args[0] = C_text::_($args[0]);
			return call_user_func_array('printf', $args);
		}
		return '';
	}
}
# 本程序是一个开源系统,使用时请你仔细阅读使用协议,商业用途请自觉购买商业授权.
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
?>